{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <form class="form form-horizontal" id="form" method="post" action="{:\\think\\Url::build($Request.action)}">
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"></label>
            <div class="formControls col-xs-6 col-sm-6 c-red">
                请先配置自己的邮件配置 (admin/extra/mail.php)
                <p>邮件驱动已改用 tp-mailer ，一款非常优美、功能非常强大、非常易用的扩展，能用于任何框架，详情请见
                <a class="c-blue" href="https://github.com/yuan1994/tp-mailer" target="_blank">https://github.com/yuan1994/tp-mailer</a>
                </p>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>收件地址：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" placeholder="你的邮箱地址，请勿填写别人的" name="receiver" datatype="*" nullmsg="请填写收件地址">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-primary radius">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
    <div id="markdown" class="mt-20"></div>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__LIB__/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="__LIB__/showdown/1.4.2/showdown.min.js"></script>
<script>
    $(function () {
        $("#form").Validform({
            tiptype:2,
            ajaxPost:true,
            showAllError:true,
            callback:function(ret){
                ajax_progress(ret,function () {
                    $("[name='receiver']").val('');
                });
            }
        });

        var converter = new showdown.Converter(),
                text      = $("#markdown_tpl").html();
        $("#markdown").html(converter.makeHtml(text));
    })
</script>
{literal}
<script type="text/plain" id="markdown_tpl">
---
扩展类库：
```
tp-mailer: 详情请见文档：https://github.com/yuan1994/tp-mailer
```
html 代码：
```
<form class="form form-horizontal" id="form" method="post" action="{:\\think\\Request::instance()->baseUrl()}">
    <div class="row cl">
        <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>收件地址：</label>
        <div class="formControls col-xs-6 col-sm-6">
            <input type="text" class="input-text" placeholder="你的邮箱地址，请勿填写别人的" name="receiver" datatype="*" nullmsg="请填写收件地址">
        </div>
        <div class="col-xs-3 col-sm-3"></div>
    </div>

    <div class="row cl">
        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
            <button type="submit" class="btn btn-primary radius">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
            <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
        </div>
    </div>
</form>
```
javascript 代码：
```
$("#form").Validform({
    tiptype:2,
    ajaxPost:true,
    showAllError:true,
    callback:function(ret){
        ajax_progress(ret,function () {
            $("[name='receiver']").val('');
        });
    }
});
```
php 代码：
```
$receive = $this->request->post("receiver");
$result = $this->validate(
    ['receiver' => $receive],
    ['receiver|收件人' => 'require|email']
);
if ($result !== true) {
    return ajax_return_adv_error($result);
}
$mailer = Mailer::instance();
$result = $mailer->to($receive)
    ->subject('来自tpadmin的测试邮件')
    ->view('mail_template')
    ->send();

if ($result == 0) {
    return ajax_return_adv_error($mailer->getError());
} else {
    return ajax_return_adv("邮件发送成功，请注意查收", '');
}
```
</script>
{/literal}
{/block}